package org.oschina.handler.validator.filter;

import org.apache.commons.lang.StringUtils;
import org.oschina.api.manage.illegalchar.service.IllegalCharService;
import org.oschina.handler.validator.IFilter;
import org.oschina.handler.validator.ValidateBean;
import org.oschina.util.JsoupUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 只允许字符串
 */
@Component
public class TextOnlyFilter implements IFilter {

	@Autowired
	private IllegalCharService illegalCharService;
	
	@Override
	public void execute(ValidateBean validateBean)
	{
		if(!StringUtils.isBlank(validateBean.getValue()))
		{
			validateBean.setValue(JsoupUtil.none(StringUtils.trim(validateBean.getValue())));
			validateBean.setValue(illegalCharService._clean(validateBean.getValue()));
		}
	}

}